package com.xhtt.modules.task.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.xhtt.common.file.FileInfoModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 排车任务-主任务
 * </p>
 *
 * @author feipc
 * @since 2019-02-26
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class TaskCarTask extends Model<TaskCarTask> {

    public static final String CarPlanId = "car_plan_id";
    public static final String UserId = "user_id";
    public static final String HeavyWeighDate = "heavy_weigh_date";
    public static final String PrintDate = "print_date";
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private Integer carPlanId;

    private Integer userId;//任务操作人

    @TableField(exist = false)
    private String stageName;//台号 名称

    @TableField(exist = false)
    private Integer islandId;//岛id

    /**
     * 任务名称
     */
    private String name;

    /**
     * 1计划保存2待装3装车中9装车完成
     */
    private Integer status;

    /**
     * 上台时间
     */
    private LocalDateTime stageUpDate;

    /**
     * 启泵时间
     */
    private LocalDateTime pumpUpDate;

    /**
     * 停泵时间
     */
    private LocalDateTime pumpDownDate;

    /**
     * 下台时间
     */
    private LocalDateTime stageDownDate;

    private LocalDateTime heavyWeighDate;//重车过磅时间

    private LocalDateTime printDate;//打印磅单时间

    /**
     * 记录人
     */
    private String recordUser;

    /**
     * 拍照
     */
    private String photo;

    @TableField(exist = false)
    private List<FileInfoModel> files;

    /**
     * 备注
     */
    private String memo;

    private Integer msgStatus;//消息发送状态 1 发送了0 没发送

    /**
     * 开始时间
     */
    private LocalDateTime startDate;

    /**
     * 完成时间
     */
    private LocalDateTime finishDate;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 最后一次调整时间
     */
    @TableField(update = "now()")
    private LocalDateTime updateTime;

    /**
     * 创建者ID，人工系统创建为0
     */
    private Integer createUserId;

    /**
     * 最后一次调整者ID
     */
    private Integer updateUserId;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public List<FileInfoModel> getFiles() {
        if (CollectionUtils.isNotEmpty(files)) {
            return files;
        }
        if (StringUtils.isEmpty(photo)) {
            return Collections.EMPTY_LIST;
        } else {
            return JSON.parseArray(photo, FileInfoModel.class);
        }
    }
}
